package com.un.ebs.quality.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.un.ebs.core.util.WebResult;
import com.un.ebs.core.util.WebUtils;
import com.un.ebs.quality.domain.QualityDefine;
import com.un.ebs.quality.dto.QualityDefineCheckListDto;
import com.un.ebs.quality.dto.QualityDefineUpdateDto;
import com.un.ebs.quality.enums.QualityTypeEnum;
import com.un.ebs.quality.service.QualityDefineService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (QualityDefine)表控制层
 *
 * @author liubo
 * @since 2020-11-15 20:12:24
 */
@RestController
@RequestMapping("/qualityDefine")
@Api(value = "quality-define")
public class QualityDefineController {

    @Resource
    private QualityDefineService service;

    @PostMapping("save")
    @ApiOperation(value = "新增或更新")
    public WebResult save(@RequestBody @Validated QualityDefineUpdateDto req) {
        service.save(req);
        return WebUtils.success();
    }

    @PostMapping("delete")
    @ApiOperation(value = "删除")
    public WebResult delete(@RequestParam String id) {
        service.delete(id);
        return WebUtils.success();
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "详情")
    public WebResult<QualityDefine> queryById(@PathVariable(name = "id") String id) {
        return WebUtils.success(service.queryById(id));
    }

    @GetMapping("list")
    @ApiOperation(value = "查询，所有质量定义")
    public WebResult<Page<QualityDefineCheckListDto>> query(@RequestParam(required = false) String searchText, @RequestParam(required = false) QualityTypeEnum type, @RequestParam(required = false) String productionWorkOrderId, @RequestParam(required = false) Double planCheckQty, @RequestParam Integer pageSize, @RequestParam Integer pageIndex) {
        return WebUtils.success(service.query(searchText, type, productionWorkOrderId, planCheckQty, pageSize, pageIndex));
    }
}